package _21define;

import java.io.File;

public class Delete {
    public static void main(String[] args) {
        File dir=new File("E:\\deleteexercise2");
        if (deleteOne(dir)) {
            System.out.println ("成功删除目录及其内容");
        } else {
            System.out.println ("删除失败");
        }

    }
    public static boolean deleteOne(File dir){
        if (dir==null||!dir.exists()){
            return true;
        }
        File[] files=dir.listFiles();
        for (File file : files) {
            if (file.isFile()){
                file.delete();
            } else {
                deleteOne(file);
            }
        }
        return dir.delete();
    }
}
